package org.jpush.core;

import org.jpush.packages.OutgoingPacket;

public class ChannelManager extends AbstractChannelManager
{
	private Server serverImpl;
	
	public ChannelManager(Server serverImpl)
	{
		this.serverImpl = serverImpl;
	}

	protected void activateSubscribers(String channelName)
	{
		serverImpl.getBroadcastStreamerManager().reshuffle();
	}

	protected void deleteOutgoingPacket(OutgoingPacket packet)
	{
		serverImpl.disposeOutgoingPacket(packet);
	}

	protected void preEncodeOutgoingPacket(OutgoingPacket packet)
	{
		serverImpl.encodeOnAllProtocols(packet);
	}

	protected void reportOnBeforePushPacket(String channelName)
	{
		serverImpl.getServerStats().addToDistribution(
				ServerStats.Measures.QoSFillRatePerChannel, channelName, 1);
	}

	protected void reportOnAfterPacketIsSent(String channelName, String subscriberKey)
	{
		serverImpl.getServerStats().addToDistribution(ServerStats.Measures.QoSSendRatePerChannel,channelName, 1);
		serverImpl.getServerStats().addToKeyedDistributionDuration(ServerStats.Measures.QoSAvgSendRatePerChannel, channelName, subscriberKey, 1);
	}
}
